package com.xbts.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnBalanceOrder;
import com.xbts.system.service.ICnBalanceOrderService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 余额充值订单Controller
 * @author xbts
 * @date 2023-08-16
 */
@Api("余额充值订单")
@RestController
@RequestMapping("/system/balance/order")
public class CnBalanceOrderController extends BaseController {

    @Autowired
    private ICnBalanceOrderService cnBalanceOrderService;

    /**
     * 查询余额充值订单列表
     */
    @ApiOperation("查询余额充值订单列表")
    @PreAuthorize("@ss.hasPermi('system:balanceOrder:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody CnBalanceOrder cnBalanceOrder) {
        startPage(cnBalanceOrder);
        List<CnBalanceOrder> list = cnBalanceOrderService.selectCnBalanceOrderList(cnBalanceOrder);
        return getDataTable(list);
    }

    /**
     * 导出余额充值订单列表
     */
    @ApiOperation("导出余额充值订单列表")
    @PreAuthorize("@ss.hasPermi('system:balanceOrder:export')")
    @Log(title = "余额充值订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody CnBalanceOrder cnBalanceOrder) {
        List<CnBalanceOrder> list = cnBalanceOrderService.selectCnBalanceOrderList(cnBalanceOrder);
        ExcelUtil<CnBalanceOrder> util = new ExcelUtil<CnBalanceOrder>(CnBalanceOrder.class);
        util.exportExcel(response, list, "余额充值订单数据");
    }

    /**
     * 获取余额充值订单详细信息
     */
    @ApiOperation("获取余额充值订单详细信息")
    @ApiImplicitParam(name = "balanceId", value = "余额充值订单ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:balanceOrder:query')")
    @GetMapping(value = "/{balanceId}")
    public AjaxResult getInfo(@PathVariable("balanceId") String balanceId) {
        return success(cnBalanceOrderService.selectCnBalanceOrderByBalanceId(balanceId));
    }

    /**
     * 新增余额充值订单
     */
    @ApiOperation("新增余额充值订单")
    @PreAuthorize("@ss.hasPermi('system:balanceOrder:add')")
    @Log(title = "余额充值订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnBalanceOrder cnBalanceOrder) {
        return success(cnBalanceOrderService.insertCnBalanceOrder(cnBalanceOrder));
    }

    /**
     * 修改余额充值订单
     */
    @ApiOperation("修改余额充值订单")
    @PreAuthorize("@ss.hasPermi('system:balanceOrder:edit')")
    @Log(title = "余额充值订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnBalanceOrder cnBalanceOrder) {
        return toAjax(cnBalanceOrderService.updateCnBalanceOrder(cnBalanceOrder));
    }

    /**
     * 删除余额充值订单
     */
    @ApiOperation("删除余额充值订单")
    @ApiImplicitParam(name = "balanceIds", value = "余额充值订单ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:balanceOrder:remove')")
    @Log(title = "余额充值订单", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> balanceIds) {
        return toAjax(cnBalanceOrderService.deleteCnBalanceOrderByBalanceIds(balanceIds));
    }
}
